package org.acghub.mtdb.xmlgen.maker.bean;

import org.acghub.mtdb.common.Bean;
import org.acghub.mtdb.common.Config;
import org.acghub.mtdb.core.TBean;
import org.acghub.mtdb.util.StringUtil;
import org.acghub.mtdb.xmlgen.Maker;
import org.acghub.mtdb.xmlgen.visitor.VarOnConstructorVisitor;

import java.io.PrintStream;

public class BeanOnConstructorMaker extends Maker<Bean> {

    private final PrintStream ps;
    private final String prefix;

    public BeanOnConstructorMaker(Bean inner, Config config, PrintStream ps, String prefix) {
        super(inner, config);
        this.ps = ps;
        this.prefix = prefix;
    }

    private String getBaseClassName() {
        return TBean.class.getCanonicalName();
    }

    @Override
    public void make() throws Exception {
        ps.println(prefix + "@Override");
        ps.println(prefix + "protected void onConstructor() {");
        this.inner().getVars().forEach(var -> var.accept(new VarOnConstructorVisitor(var, ps, StringUtil.concat(prefix, StringUtil.TAB))));
        ps.println(prefix + "}");
        ps.println();
    }
}
